package com.hadoop.chapter2;

import java.io.IOException;

import org.apache.hadoop.io.FloatWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.lang.String;

public class MaxTemperatureMapper extends Mapper<LongWritable,Text,Text,FloatWritable>{

	private static final float MISSING = 9999;
	@Override
	public void map(LongWritable key, Text value, Context context) 
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		//
		String[] line = value.toString().split("\\s+");
		String year = line[2].substring(0, 4);
		float airTemp=Float.parseFloat(line[3]);
		if(airTemp == MISSING)
		{
			airTemp=0;
		}
		System.out.println("----------------map--------------");
		System.out.println("year:"+year+" ,temperature:"+airTemp);
		context.write(new Text(year), new FloatWritable(airTemp));
	}
	
	@org.junit.Test
	public void Test()
	{
		System.out.println("coming");
		String t="030050 99999  19291001    45.3  4    40.0  4  1001.6  4  9999.9  0   17.1  4    4.5  4    8.9  999.9    51.1    44.1*  0.00I 999.9  000000";
		String[] line = t.toString().split("\\s+");
		String year = line[2].substring(0, 3);
		System.out.println(year);
		
	}
	
}
